<!DOCTYPE html>
<html>
 <head> 
  <meta charset="UTF-8" /> 
  <title>分配权限</title> 
  <link rel="stylesheet" href="../webjars/plugins/layui/css/layui.css" media="all" /> 
  <link rel="stylesheet" href="../webjars/css/global.css" media="all" /> 
  <style type="text/css">
     .applist{background-color:#FFFFE0;border-right: 1px solid #ddd; margin-left:20px;}
     .applist .appitem{
        float:left;width:45%;padding-left:10px;padding-bottom:10px;
     }
     .applist .appitem .name {font-size: 16px;}
     .listright {
        margin-top:5px;
       text-align: center;
     }
  </style> 
 </head> 
 <body> 
  <div id="list_cont" class="admin-main"></div> 
<script type="text/html" id="list_tpl">
{{# layui.each(d, function(index, item){ }}
<div>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;"> 
    <legend>{{item.envName}}({{item.env}})</legend> 
   </fieldset> 
   <div class="layui-row"> 
    <div class="layui-col-md10 applist"> 
     {{# layui.each(item.perms, function(index, item2){ }}
     <div class="appitem"><span class="name">{{item2.appName}}</span>&nbsp;<span class="layui-badge  layui-bg-{{item2.operate === 'RO' ? 'orange' : 'blue'}}">{{item2.operate === 'RO' ? '可查看' : '可编辑'}}</span></div> 
     {{# }); }}
    </div> 
    <div class="layui-col-md1 listright"> 
     <button type="button" class="layui-btn layui-btn-normal layui-btn-sm J_edit" data-env="{{item.env}}">编辑</button> 
    </div> 
   </div>
</div>
{{# }); }}
</script> 
<script type="text/javascript" src="../webjars/plugins/layui/layui.js"></script> 
<script>
layui.config({
	  base: '/webjars/js/'
}).use(['laytpl','jeesuitelayui'], function() {
  var $ = layui.jquery,laytpl = layui.laytpl,jeesuitelayui = layui.jeesuitelayui;
  var userId = jeesuitelayui.getQueryParams('id');
  jeesuitelayui.get('/admin/user/get_user_permissions?userId=' + userId,function(data){
	  var tpl = $('#list_tpl').html();
		laytpl(tpl).render(data, function(html){
			$('#list_cont').html(html);
	 });
  });
  
  $('body').on('click','.J_edit', function(){
		var self = $(this),env = self.attr('data-env');
		var url = 'selectPermission.html?userId='+userId + '&env=' + env;
		layer.open({
			  type: 2,
			  title: '编辑权限',
			  shadeClose: true,
			  shade: 0.3,
			  area: ['450px', '550px'],
			  content: url
			}); 
	});
 });
 
</script>  
 </body>
</html>